#ifndef THREAD_CONTAINER_H
#define THREAD_CONTAINER_H

#include "worker_thread.h"
#include "listener.h"
#include "notifier.h"
#include "receiver.h"

#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>

#include <list>

using namespace std;

namespace network {
	class thread_container : public network::listener {
	public:
		typedef boost::shared_ptr<network::worker_thread> thrd_ptr;
		typedef boost::shared_ptr<const network::worker_thread> 
			const_thrd_ptr;

		thread_container() {}
		virtual ~thread_container() {interrupt();}

		void add(thrd_ptr p);
		void remove(thrd_ptr p);
		thrd_ptr find(const network::worker_thread *thrd);
		void join_all();
		void interrupt();
		void start_threads();

		virtual void notify(const network::notifier *n);
	private:
		list<thrd_ptr> _list;
		boost::mutex _mon;
	};
}

#endif
